package com.ruoyi.project.treat.controller;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysPost;
import com.ruoyi.project.treat.domain.SystemDrug;
import com.ruoyi.project.treat.domain.TreatPatient;
import com.ruoyi.project.treat.domain.TreatPatientHistory;
import com.ruoyi.project.treat.service.ITreatNewVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/treat/newvisit")
public class TreatNewVisitController extends BaseController {
    @Autowired
    private ITreatNewVisitService newVisitService;

    /**
     * 根据挂号Id获取挂号详细信息
     */
    @PreAuthorize("@ss.hasPermi('treat:newvisit:query')")
    @GetMapping(value = "/{registerId}")
    public AjaxResult getInfo(@PathVariable String registerId)
    {
        System.out.println(newVisitService.selectPatientByRegisterId(registerId));
        return AjaxResult.success(newVisitService.selectPatientByRegisterId(registerId));
    }

    /**
     * 新增病历信息
     */
    @PreAuthorize("@ss.hasPermi('treat:newvisit:add')")
    @Log(title = "新开就诊", businessType = BusinessType.INSERT)
    @PostMapping("addPatientHistory")
    public int add(TreatPatientHistory patientHistory)
    {
        patientHistory.setCreateBy(SecurityUtils.getUsername());
        int i = newVisitService.insertPatientHistory(patientHistory);
        System.out.println(i);
        return i;
    }

    /**
     * 根据患者Id获取病例详细信息
     */
    @PreAuthorize("@ss.hasPermi('treat:newvisit:query')")
    @GetMapping("patienthistory")
    public TableDataInfo getPatientHistoryInfo(String patientId)
    {
        List<TreatPatientHistory> list = newVisitService.selectPatientHistoryByPatientId(patientId);
        return getDataTable(list);
    }

    /**
     * 查询药品处方信息
     */
    @PreAuthorize("@ss.hasPermi('treat:newvisit:query')")
    @GetMapping("listdrug")
    public TableDataInfo getDrugInfo(String drugName)
    {
        List<SystemDrug> list = newVisitService.selectSystemDrugList(drugName);
        return getDataTable(list);
    }
}
